import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { CustomerSimpleManage } from '../../customer-simple-manage/entities/customer-simple-manage.entity';
import { Msbmanage } from '../../msbmanage/entities/msbmanage.entity';

@Entity('customer_simple_child')
export class CustomerSimpleChild {
  @PrimaryGeneratedColumn()
  _Identify: number;

  @Column()
  _Locked: boolean;

  @Column()
  _SortKey: number;

  @Column({ type: 'nvarchar', length: 50 })
  simpleid: string;

  @Column()
  category: string;

  @Column()
  count: number;

  @Column()
  detail: string;

  @Column()
  productname: string;

  @ManyToOne(
    () => CustomerSimpleManage,
    (customerSimpleManage) => customerSimpleManage.children,
  )
  // 注意这里referencedColumnName: 'manageid'，对应customerSimpleManage中指定manageid 作为关联字段
  // 本来是默认主键作为关联字段
  @JoinColumn({ name: 'manageid', referencedColumnName: 'manageid' }) // 显式指定外键列
  manage: CustomerSimpleManage;

  // ManyToOne 关联到 msb_simple_manage 表的 msbmanageidcode
  @ManyToOne(
    () => Msbmanage,
    (msbSimpleManage) => msbSimpleManage.customersimplechild,
  )
  @JoinColumn({ name: 'simpleid', referencedColumnName: 'msbmanageidcode' }) // 显式指定外键和关联字段
  msbSimpleManage: Msbmanage;
}
